/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmAltaCompra.java
 *
 * Created on 12/11/2011, 09:46:07 AM
 */
package Compras;

import Beans.BancoBean;
import Beans.CompraBean;
import Beans.EstatusBean;
import Beans.ProductoBean;
import Beans.ProveedorBean;
import Blogic.BancoBLogic;
import Blogic.CompraBLogic;
import Blogic.EstatusBLogic;
import Blogic.ProductoBLogic;
import Blogic.ProveedorBLogic;
import Ventas.frmBusquedaProductos;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author orellana
 */
public class frmAltaCompra extends javax.swing.JFrame {

    // Atributos de la Clase
//    int tipoAccion = 0;
//    private Date fecha = new Date();
//    public String col[] = {"Clave", "Producto", "Cantidad", "Costo", "Subtotal", "I.V.A", "Total"};
//    public DefaultTableModel modelOrden = new DefaultTableModel(col, 0);
//    modelOrden.setColumnIdentifiers(col);
    DefaultTableModel modelOrden = new DefaultTableModel();
    int tipoAccion = 0;
    private ProductoBean buscarProductoCompra = null;
    // Buscar Producto
    //private frmBusquedaProductos frmBusquedaProductos=new frmBusquedaProductos();
    private frmBusquedaProductos frmBusquedaProductos=new frmBusquedaProductos();

     private String idProducto="-1";
    /** Creates new form frmAltaCompra */
    public frmAltaCompra(int tipo) {
        initComponents();

        String col[] = {"Codigo", "Producto", "Cantidad", "Costo", "Subtotal", "I.V.A", "Total"};
        modelOrden.setColumnIdentifiers(col);
        this.tblOrdenCompra.setModel(modelOrden);


        // Definimos la ubicación del formulario
        this.setLocationRelativeTo(null);
        //definimos el redimencionamiento
        this.setResizable(false);
        // Definimos el cerrado de la ventana
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        // Definimos el tamaño de las columnas (Tabla)
        getTablaOrden();
        // Seteamos el Titulo del Formulario
        switch (tipo) {
            // Alta de Compra
            case 1:
                this.setTitle(".:: Alta de Compras ::.");
                jTabbedPane1.setTitleAt(0, "Alta de Compra");
                this.tipoAccion = 1;
                break;

            // Modificacion de Compra
            case 2:
                this.setTitle(".:: Modificar Compras ::.");
                jTabbedPane1.setTitleAt(0, "Modificar Compra");
                this.tipoAccion = 2;
                break;
        }
        obtProveedoresCombo();

        obtBancosCombo();

        obtEstatusCombo();

        obtFechasDefecto();

        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jcbStatusOrdenCompra = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtNoRecibo = new javax.swing.JTextField();
        jcbProveedor = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txtNoFactura = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtNoFactura1 = new javax.swing.JTextField();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblOrdenCompra = new javax.swing.JTable();
        jLabel19 = new javax.swing.JLabel();
        txtSubtotal = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtIva = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        txtCodigoProducto = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txtCantidadProducto = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        txtPrecioProducto = new javax.swing.JTextField();
        btnDetalle = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtDescuento = new javax.swing.JTextField();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();

        jPopupMenu1.setName("jPopupMenu1"); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemapegasso.SistemaPegassoApp.class).getContext().getResourceMap(frmAltaCompra.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        jButton1.setIcon(resourceMap.getIcon("btnGuardar.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("btnGuardar.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("btnGuardar.toolTipText")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("btnGuardar"); // NOI18N
        jButton1.setPreferredSize(new java.awt.Dimension(28, 34));
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("jButton2.toolTipText")); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setPreferredSize(new java.awt.Dimension(28, 34));
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setBackground(resourceMap.getColor("jLabel1.background")); // NOI18N
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setOpaque(true);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jcbStatusOrdenCompra.setFont(resourceMap.getFont("jcbStatusOrdenCompra.font")); // NOI18N
        jcbStatusOrdenCompra.setForeground(resourceMap.getColor("jcbStatusOrdenCompra.foreground")); // NOI18N
        jcbStatusOrdenCompra.setMinimumSize(new java.awt.Dimension(69, 21));
        jcbStatusOrdenCompra.setName("jcbStatusOrdenCompra"); // NOI18N
        jcbStatusOrdenCompra.setPreferredSize(new java.awt.Dimension(69, 21));

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        txtNoRecibo.setFont(resourceMap.getFont("txtNoRecibo.font")); // NOI18N
        txtNoRecibo.setName("txtNoRecibo"); // NOI18N

        jcbProveedor.setFont(resourceMap.getFont("jcbProveedor.font")); // NOI18N
        jcbProveedor.setMinimumSize(new java.awt.Dimension(69, 21));
        jcbProveedor.setName("jcbProveedor"); // NOI18N
        jcbProveedor.setPreferredSize(new java.awt.Dimension(69, 21));
        jcbProveedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jcbProveedorMouseClicked(evt);
            }
        });
        jcbProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbProveedorActionPerformed(evt);
            }
        });

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        txtNoFactura.setName("txtNoFactura"); // NOI18N
        txtNoFactura.setPreferredSize(new java.awt.Dimension(10, 21));

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        txtNoFactura1.setFont(resourceMap.getFont("txtNoOrden.font")); // NOI18N
        txtNoFactura1.setEnabled(false);
        txtNoFactura1.setName("txtNoOrden"); // NOI18N
        txtNoFactura1.setPreferredSize(new java.awt.Dimension(10, 21));

        jDateChooser1.setEnabled(false);
        jDateChooser1.setName("jdcFechaCaptura"); // NOI18N

        jDateChooser2.setName("jdcFechaCompletada"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1022, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7)
                    .addComponent(jLabel11))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcbStatusOrdenCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNoFactura1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 148, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))
                        .addGap(137, 137, 137)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtNoRecibo)
                            .addComponent(txtNoFactura, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addContainerGap(44, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jcbProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel11)
                        .addComponent(txtNoFactura1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(txtNoFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jDateChooser1, 0, 0, Short.MAX_VALUE))
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(txtNoRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE))
                    .addComponent(jcbStatusOrdenCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jLabel2)))
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jcbProveedor, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
                .addGap(8, 8, 8))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jLabel13.setBackground(resourceMap.getColor("jLabel13.background")); // NOI18N
        jLabel13.setFont(resourceMap.getFont("jLabel13.font")); // NOI18N
        jLabel13.setForeground(resourceMap.getColor("jLabel13.foreground")); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N
        jLabel13.setOpaque(true);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblOrdenCompra.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Producto", "Categoría", "Cantidad", "Costo", "Subtotal", "Iva", "Total"
            }
        ));
        tblOrdenCompra.setGridColor(resourceMap.getColor("tblOrdenCompra.gridColor")); // NOI18N
        tblOrdenCompra.setName("tblOrdenCompra"); // NOI18N
        tblOrdenCompra.setSelectionBackground(resourceMap.getColor("tblOrdenCompra.selectionBackground")); // NOI18N
        jScrollPane1.setViewportView(tblOrdenCompra);
        tblOrdenCompra.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title0")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title1")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title2")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title3")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title4")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title5")); // NOI18N
        tblOrdenCompra.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("tblOrdenCompra.columnModel.title6")); // NOI18N

        jLabel19.setFont(resourceMap.getFont("jLabel19.font")); // NOI18N
        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        txtSubtotal.setFont(resourceMap.getFont("txtSubtotal.font")); // NOI18N
        txtSubtotal.setText(resourceMap.getString("txtSubtotal.text")); // NOI18N
        txtSubtotal.setName("txtSubtotal"); // NOI18N

        jLabel20.setFont(resourceMap.getFont("jLabel20.font")); // NOI18N
        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        txtIva.setFont(resourceMap.getFont("txtIva.font")); // NOI18N
        txtIva.setText(resourceMap.getString("txtIva.text")); // NOI18N
        txtIva.setName("txtIva"); // NOI18N

        jLabel21.setFont(resourceMap.getFont("jLabel21.font")); // NOI18N
        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        txtTotal.setFont(resourceMap.getFont("txtTotal.font")); // NOI18N
        txtTotal.setText(resourceMap.getString("txtTotal.text")); // NOI18N
        txtTotal.setName("txtTotal"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("jPanel2.border.outsideBorder.matteColor")), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, resourceMap.getColor("jPanel2.border.insideBorder.highlightOuterColor"), resourceMap.getColor("jPanel2.border.insideBorder.highlightInnerColor"), null, null))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel15.setFont(resourceMap.getFont("jLabel15.font")); // NOI18N
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        txtCodigoProducto.setFont(resourceMap.getFont("txtCodigoProducto.font")); // NOI18N
        txtCodigoProducto.setText(resourceMap.getString("txtCodigoProducto.text")); // NOI18N
        txtCodigoProducto.setName("txtCodigoProducto"); // NOI18N
        txtCodigoProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoProductoActionPerformed(evt);
            }
        });
        txtCodigoProducto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCodigoProductoFocusLost(evt);
            }
        });
        txtCodigoProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCodigoProductoKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCodigoProductoKeyReleased(evt);
            }
        });

        jLabel17.setFont(resourceMap.getFont("jLabel17.font")); // NOI18N
        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel14.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        txtCantidadProducto.setFont(resourceMap.getFont("txtCantidadProducto.font")); // NOI18N
        txtCantidadProducto.setName("txtCantidadProducto"); // NOI18N

        jLabel18.setFont(resourceMap.getFont("jLabel18.font")); // NOI18N
        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        txtPrecioProducto.setFont(resourceMap.getFont("txtCostoProducto.font")); // NOI18N
        txtPrecioProducto.setName("txtCostoProducto"); // NOI18N
        txtPrecioProducto.setPreferredSize(new java.awt.Dimension(10, 21));

        btnDetalle.setIcon(resourceMap.getIcon("btnAgregarProducto.icon")); // NOI18N
        btnDetalle.setText(resourceMap.getString("btnAgregarProducto.text")); // NOI18N
        btnDetalle.setToolTipText(resourceMap.getString("btnAgregarProducto.toolTipText")); // NOI18N
        btnDetalle.setName("btnAgregarProducto"); // NOI18N
        btnDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetalleActionPerformed(evt);
            }
        });

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jTextField1.setFont(resourceMap.getFont("txtNombreProducto.font")); // NOI18N
        jTextField1.setText(resourceMap.getString("txtNombreProducto.text")); // NOI18N
        jTextField1.setEnabled(false);
        jTextField1.setName("txtNombreProducto"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addGap(3, 3, 3)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel10))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtCodigoProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel17)
                        .addGap(4, 4, 4)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)
                        .addGap(3, 3, 3)
                        .addComponent(txtCantidadProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)
                        .addComponent(jLabel18)
                        .addGap(6, 6, 6)
                        .addComponent(txtPrecioProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnDetalle, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(txtCodigoProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(2, 2, 2)
                        .addComponent(jLabel10))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btnDetalle, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(txtCantidadProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18)
                            .addComponent(txtPrecioProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        txtDescuento.setFont(resourceMap.getFont("txtDescuento.font")); // NOI18N
        txtDescuento.setText(resourceMap.getString("txtDescuento.text")); // NOI18N
        txtDescuento.setName("txtDescuento"); // NOI18N

        jCheckBox1.setFont(resourceMap.getFont("cbxCompraIva.font")); // NOI18N
        jCheckBox1.setText(resourceMap.getString("cbxCompraIva.text")); // NOI18N
        jCheckBox1.setName("cbxCompraIva"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel12.setBackground(resourceMap.getColor("jLabel12.background")); // NOI18N
        jLabel12.setFont(resourceMap.getFont("jLabel12.font")); // NOI18N
        jLabel12.setForeground(resourceMap.getColor("jLabel12.foreground")); // NOI18N
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N
        jLabel12.setOpaque(true);

        jTextField2.setFont(resourceMap.getFont("txtContado.font")); // NOI18N
        jTextField2.setText(resourceMap.getString("txtContado.text")); // NOI18N
        jTextField2.setName("txtContado"); // NOI18N
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel16.setBackground(resourceMap.getColor("lbl.background")); // NOI18N
        jLabel16.setFont(resourceMap.getFont("lbl.font")); // NOI18N
        jLabel16.setForeground(resourceMap.getColor("lbl.foreground")); // NOI18N
        jLabel16.setText(resourceMap.getString("lbl.text")); // NOI18N
        jLabel16.setName("lbl"); // NOI18N
        jLabel16.setOpaque(true);

        jTextField3.setFont(resourceMap.getFont("txtCredito.font")); // NOI18N
        jTextField3.setText(resourceMap.getString("txtCredito.text")); // NOI18N
        jTextField3.setName("txtCredito"); // NOI18N

        jLabel22.setBackground(resourceMap.getColor("jLabel22.background")); // NOI18N
        jLabel22.setFont(resourceMap.getFont("jLabel22.font")); // NOI18N
        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        jTextField4.setFont(resourceMap.getFont("txtNoCheque.font")); // NOI18N
        jTextField4.setText(resourceMap.getString("txtNoCheque.text")); // NOI18N
        jTextField4.setName("txtNoCheque"); // NOI18N

        jComboBox1.setFont(resourceMap.getFont("jcbBanco.font")); // NOI18N
        jComboBox1.setName("jcbBanco"); // NOI18N

        jLabel23.setBackground(resourceMap.getColor("jLabel23.background")); // NOI18N
        jLabel23.setFont(resourceMap.getFont("jLabel23.font")); // NOI18N
        jLabel23.setText(resourceMap.getString("jLabel23.text")); // NOI18N
        jLabel23.setName("jLabel23"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 1054, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1030, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 1030, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1030, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, 0)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField3)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(jLabel8)
                        .addGap(129, 129, 129)
                        .addComponent(jLabel22)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jLabel23)))
                .addGap(107, 107, 107)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(jLabel20)
                    .addComponent(jLabel21))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtIva)
                        .addComponent(txtSubtotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19)
                            .addComponent(jLabel8)
                            .addComponent(txtDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtIva, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel20))
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel21)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jCheckBox1))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(jLabel23))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, 0)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Obtiene tamaño columnas tablas
    public void getTablaOrden() {
        // Vaciamos el modelo con los datos
        tblOrdenCompra.setModel(modelOrden);
        // Definimos el tamaño de las columnas
        // codigo
        tblOrdenCompra.getColumnModel().getColumn(0).setPreferredWidth(8);
        // nombre producto
        tblOrdenCompra.getColumnModel().getColumn(1).setPreferredWidth(40);
        // Cantidad
        tblOrdenCompra.getColumnModel().getColumn(2).setPreferredWidth(4);
        // Costo
        tblOrdenCompra.getColumnModel().getColumn(3).setPreferredWidth(4);
        // IVA
        tblOrdenCompra.getColumnModel().getColumn(4).setPreferredWidth(4);
        // Subtotal
        tblOrdenCompra.getColumnModel().getColumn(5).setPreferredWidth(4);
        // Total
        tblOrdenCompra.getColumnModel().getColumn(6).setPreferredWidth(4);
        // 
        //tblOrdenCompra.getColumnModel().getColumn(7).setMinWidth(0);
        //tblOrdenCompra.getColumnModel().getColumn(7).setMaxWidth(0);
    }
    //Obtenemos los proveedores

    private void obtProveedoresCombo() {
        //System.out.println("Entre en obtproveedor");
        // Variables Locales
        ProveedorBean sqlBean = new ProveedorBean();
        Vector proveedores = new Vector();

        // Ejecutamos la Consulta
        proveedores = (new ProveedorBLogic()).buscarDatosProveedorCombo(sqlBean);
        // Agregamos el Valor por Default
        jcbProveedor.addItem("Seleccione");
        // Vaciamos los Datos
        for (int i = 0; i < proveedores.size(); i++) {
            ProveedorBean datoProveedores = new ProveedorBean();
            datoProveedores = (ProveedorBean) proveedores.elementAt(i);
            // Agregamos los Datos
            jcbProveedor.addItem(datoProveedores.getNombreProveedor());
        }

        // Definimos la Accion del Combo
        jcbProveedor.setActionCommand("cmbEstadoCliente");
//       jcbProveedor.addActionListener(new ActionListener() {
//
//          public void actionPerformed(ActionEvent ae) {
//                // Accion jcbEstadoCliente
//                if (ae.getActionCommand().equals("cmbEstadoCliente")){
//                    // Obtenemos las Ciudades
//                    obtCiudades();
    }
//            }
//        });
//    }

    private void obtFechasDefecto() {
        // Variables Locales
        Date fecha = new Date();
        // Seteamos los Datos
        jDateChooser1.setDate(fecha);
        jDateChooser2.setDate(fecha);
    }

    //Obtenemos los proveedores
    private void obtBancosCombo() {
        //System.out.println("Entre en obtproveedor");
        // Variables Locales
        BancoBean sqlBean = new BancoBean();
        Vector bancos = new Vector();

        // Ejecutamos la Consulta
        bancos = (new BancoBLogic()).buscarDatosBancoCombo(sqlBean);
        // Agregamos el Valor por Default
        jComboBox1.addItem("Seleccione");
        // Vaciamos los Datos
        for (int i = 0; i < bancos.size(); i++) {
            BancoBean datoBancos = new BancoBean();
            datoBancos = (BancoBean) bancos.elementAt(i);
            // Agregamos los Datos
            jComboBox1.addItem(datoBancos.getNombreBanco());
        }

        // Definimos la Accion del Combo
        jComboBox1.setActionCommand("cmbEstadoCliente");

    }

    //Obtenemos los proveedores
    private void obtEstatusCombo() {
        //System.out.println("Entre en obtproveedor");
        // Variables Locales
        EstatusBean sqlBean = new EstatusBean();
        Vector estatus = new Vector();

        // Ejecutamos la Consulta
        estatus = (new EstatusBLogic()).buscarDatosEstatusCombo(sqlBean);
        // Agregamos el Valor por Default
        jcbStatusOrdenCompra.addItem("Seleccione");
        // Vaciamos los Datos
        for (int i = 0; i < estatus.size(); i++) {
            EstatusBean datoEstatus = new EstatusBean();
            datoEstatus = (EstatusBean) estatus.elementAt(i);
            // Agregamos los Datos
            jcbStatusOrdenCompra.addItem(datoEstatus.getNombreEstatus());
        }

        // Definimos la Accion del Combo
        jcbStatusOrdenCompra.setActionCommand("cmbEstadoCliente");
//       jcbProveedor.addActionListener(new ActionListener() {
//
//          public void actionPerformed(ActionEvent ae) {
//                // Accion jcbEstadoCliente
//                if (ae.getActionCommand().equals("cmbEstadoCliente")){
//                    // Obtenemos las Ciudades
//                    obtCiudades();
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        // Cerramos el formulario
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jcbProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbProveedorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbProveedorActionPerformed

    private void jcbProveedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jcbProveedorMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbProveedorMouseClicked

    // boton guardar
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        // Variables Locales
//        CompraBean sqlBean=new CompraBean();
//        Vector datosCompra=new Vector();
//        ProveedorBean sqlBeanProveedor=new ProveedorBean();
//        Vector datosProveedor=new Vector();
//        BancoBean sqlBeanBanco=new BancoBean();
//        Vector datosBanco=new Vector();
//        EstatusBean sqlBeanEstatus=new EstatusBean();
//        Vector datosEstatus=new Vector();
//
//        int idBanco=0;
//        int idProveedor=0;
//        int idEstatus=0;
//        int idCompra=0;
//
//        // Validamos el Tipo de Accion a Realizar
//        switch(this.tipoAccion){
//            // Alta de Cliente
//            case 1:
//
//                // Validacion de Campos
//                if (jcbProveedor.getSelectedIndex()<0){
//                    // Mensaje al Usuario
//                    JOptionPane.showMessageDialog(null,"Seleccione un Proveedor","Validacion de Campos",JOptionPane.ERROR_MESSAGE);
//
//                }else{
//
//                    // Guardamos el registro de compras
//                    //Obtenemos el id de la compra
//                    datosCompra=(new CompraBLogic()).getDatosComprasNextId(sqlBean);
//                    sqlBean=(CompraBean) datosCompra.elementAt(0);
//                    //Vaciamos los datos
//                    idCompra=Integer.parseInt(sqlBean.getIdOrdenCompra());
//
//                    //Identificamos el id del banco seleccionado
//                    sqlBeanBanco.setNombreBanco(jComboBox1.getSelectedItem().toString());
//                    datosBanco=(new BancoBLogic()).getIdBanco(sqlBeanBanco);
//                    sqlBeanBanco=(BancoBean) datosBanco.elementAt(0);
//                    idBanco=Integer.parseInt(sqlBeanBanco.getIdBanco());
//
//                    //Identificamos el id del proveedor seleccionado
//                    sqlBeanProveedor.setNombreProveedor(jcbProveedor.getSelectedItem().toString());
//                    datosProveedor=(new ProveedorBLogic()).getIdProveedor(sqlBeanProveedor);
//                    sqlBeanProveedor=(ProveedorBean) datosProveedor.elementAt(0);
//                    idProveedor=Integer.parseInt(sqlBeanProveedor.getIdProveedor());
//
//                    //Identificamos el id del estatus seleccionado
//                    sqlBeanEstatus.setNombreEstatus(jcbStatusOrdenCompra.getSelectedItem().toString());
//                    datosEstatus=(new EstatusBLogic()).getIdEstatus(sqlBeanEstatus);
//                    sqlBeanEstatus=(EstatusBean) datosEstatus.elementAt(0);
//                    idEstatus=Integer.parseInt(sqlBeanEstatus.getIdEstatus());
//
//                     // Seteamos los Datos
////                    sqlBean.setFechaCaptura(jDateChooser1.getDateFormatString());
////                    sqlBean.setFechaCompletada(jDateChooser2.getDateFormatString());
//                    sqlBean.setIdEstatus(Integer.toString(idEstatus));
//                    sqlBean.setIdProveedor(Integer.toString(idProveedor));
//                    sqlBean.setNoFactura(txtNoFactura.getText());
//                    sqlBean.setNoRecibo(txtNoRecibo.getText());
//                    sqlBean.setDescuentoOrden(txtDescuento.getText());
//                    sqlBean.setSubtotalOrden(txtSubtotal.getText());
//                    sqlBean.setIvaOrden(txtIva.getText());
//                    sqlBean.setTotalOrden(txtTotal.getText());
//                    sqlBean.setPagoContado(jTextField2.getText());
//                    sqlBean.setPagoCredito(jTextField3.getText());
//                    sqlBean.setNoCheque(jTextField4.getText());
//                    sqlBean.setIdBanco(Integer.toString(idBanco));
//
//                    //Insertamos el registro
//                    datosCompra=(new CompraBLogic()).execute(sqlBean);
//                    //Evaluamos el resultado
//                    if(datosCompra.elementAt(0).equals("OK")){
//                    // Mensaje al usuario
//                        JOptionPane.showMessageDialog(null,"Orden de Compra Registrado Satisfactoriamente","Registro",JOptionPane.INFORMATION_MESSAGE);
//                        this.setVisible(false);
//                    }else{
//                        // Mensaje de error
//                        JOptionPane.showMessageDialog(null,"Ocurrio un Problema al Momento de Registrar la Orden de Compra","Registro",JOptionPane.INFORMATION_MESSAGE);
//                    }
//
//                }
//                break;
//
//                //Modificar
//            case 2:
//
//                 break;
//                }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtCodigoProductoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodigoProductoKeyTyped
        // TODO add your handling code here:
//       ProductoBean buscarProductoCompra = new ProductoBean();
//        Vector productoVector = new Vector();
//        ProductoBLogic productoBlogic = new ProductoBLogic();
//        buscarProductoCompra.setClaveProducto(txtCodigoProducto.getText().toString().trim());
//
//        productoVector = productoBlogic.buscarProductoByCompra(buscarProductoCompra);
//        if (productoVector.size() > 0) {
////           deleteRowModelTable();
////           for(int i=0; i<productoVector.size();i++){
//            buscarProductoCompra = (ProductoBean) productoVector.elementAt(0);
////           jTextField1.add.addRow(new Object[]{buscarMarca.getCodigoMarca(), buscarMarca.getNombreMarca(),buscarMarca.getIdMarca()});
//            jTextField1.setText(buscarProductoCompra.getNombreProducto().toString());
//            txtPrecioProducto.setText(buscarProductoCompra.getPrecioCosto().toString());
//
//        }
    }//GEN-LAST:event_txtCodigoProductoKeyTyped

    private void txtCodigoProductoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodigoProductoKeyReleased
        // TODO add your handling code here:
   buscarProductoCompra = new ProductoBean();
        Vector productoVector = new Vector();
        ProductoBLogic productoBlogic = new ProductoBLogic();
        buscarProductoCompra.setClaveProducto(txtCodigoProducto.getText().toString().trim());

        productoVector = productoBlogic.buscarProductoByCompra(buscarProductoCompra);
        if (productoVector.size() > 0) {
//           deleteRowModelTable();
//           for(int i=0; i<productoVector.size();i++){
            buscarProductoCompra = (ProductoBean) productoVector.elementAt(0);
//           jTextField1.add.addRow(new Object[]{buscarMarca.getCodigoMarca(), buscarMarca.getNombreMarca(),buscarMarca.getIdMarca()});
            jTextField1.setText(buscarProductoCompra.getNombreProducto().toString());
            txtPrecioProducto.setText(buscarProductoCompra.getPrecioCosto().toString());
            String ivaproducto= buscarProductoCompra.getIva();
        }

        // Para [F3] Buscar Producto
        if (evt.getKeyCode()==114){
            // Limpiamos el Formulario
            frmBusquedaProductos.limpiaCampos();
            // Cargamos el Formulario (Busqueda de Productos)
            frmBusquedaProductos.setVisible(true);
            // Asignamos Funcionalidad de Boton (frmBusquedaProductos)
            frmBusquedaProductos.btnAceptar.setActionCommand("btnAceptar");
            frmBusquedaProductos.btnAceptar.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // Realizamos la Accion del Boton
                    if (e.getActionCommand().equals("btnAceptar")){
                        // Vaciamos el Resultado
                        idProducto=frmBusquedaProductos.getIdProductoSel();
                        // Vaciamos el Codigo del Producto
                        txtCodigoProducto.setText(frmBusquedaProductos.getCodigoProducto());
                        // Movemos el Foco
                        txtCantidadProducto.requestFocus();
                    }
                }
            });

        }


    }//GEN-LAST:event_txtCodigoProductoKeyReleased

    private void txtCodigoProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoProductoActionPerformed
        // TODO add your handling code here:
//        ProductoBean buscarProductoCompra = new ProductoBean();
//        Vector productoVector = new Vector();
//        ProductoBLogic productoBlogic = new ProductoBLogic();
//        buscarProductoCompra.setClaveProducto(txtCodigoProducto.getText().toString().trim());
//
//        productoVector = productoBlogic.buscarProductoByCompra(buscarProductoCompra);
//        if (productoVector.size() > 0) {
////           deleteRowModelTable();
////           for(int i=0; i<productoVector.size();i++){
//            buscarProductoCompra = (ProductoBean) productoVector.elementAt(0);
////           jTextField1.add.addRow(new Object[]{buscarMarca.getCodigoMarca(), buscarMarca.getNombreMarca(),buscarMarca.getIdMarca()});
//            jTextField1.setText(buscarProductoCompra.getNombreProducto().toString());
//            txtPrecioProducto.setText(buscarProductoCompra.getPrecioCosto().toString());
//
//        }

    }//GEN-LAST:event_txtCodigoProductoActionPerformed

    private void btnDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetalleActionPerformed
        // TODO add your handling code here:

        double subtotal=0;
        double subto;
        double ivatotal=0;
        double ivatot;
        double sumatotal=0;
        double totaltot;

        ProductoBean ivaventa =buscarProductoCompra;
        // Mostramos los lados en la tabla de los productos a comprar
        String datos[]=new String[7];
        //Mostramos lo que tenga la caja de texto en el vector en la posicion deseada
        datos[0]=this.txtCodigoProducto.getText();
        //Mostramos lo que tenga la caja de texto en el vector en la posicion deseada
        datos[1]=this.jTextField1.getText();
        //Mostramos lo que tenga la caja de texto en el vector en la posicion deseada
        datos[2]=this.txtCantidadProducto.getText();
        //Mostramos lo que tenga la caja de texto en el vector en la posicion deseada
        datos[3]=this.txtPrecioProducto.getText();

        // este paso es para limpiar la caja de texto
        //this.txtPrecioProducto.setText(null);

        // Hacemos el calculo de la cantidad por el costo
        //Parseamos de string a entero
        int numero1=Integer.parseInt(txtCantidadProducto.getText().toString());
        int numero2=Integer.parseInt(txtPrecioProducto.getText().toString());
        int resultado=numero1*numero2;
        //Parseamos de entero a string para mostrar el resultado como string
        String result=Integer.toString(resultado);
        //y lo metemos en el vector y en su posicion en la tabla
        datos[4]=result;
        //obtenemos el iva que tiene el producto
        String ivaproducto= ivaventa.getIva();
        //para hacer la operacion y el calculo del iva parseamos a double
        double ivadouble = Double.valueOf(ivaproducto).doubleValue();
        double resultdouble = Double.valueOf(result).doubleValue();
        //Hacemos el calculo de iva en formato double
        double totaliva=resultdouble * ivadouble;
        System.out.println(" imprime aa..... "+totaliva);

        //Delimitamos los decimales a recibir
        //Indicamos el simbolo a utilizar como separador en este caso sera el PUNTO DECIMAL
        DecimalFormatSymbols simbolo = new DecimalFormatSymbols();
        simbolo.setDecimalSeparator('.');
        DecimalFormat formateador= new DecimalFormat("#.##",simbolo);
        //Insertamos el valor delimitado en una variable
        double aa = Double.valueOf(formateador.format(totaliva));
        //Parceamos de double a string
        String ivacomplemento=String.valueOf(aa);
//        System.out.println(" imprime aa..... "+aa);
        //Mostramos el resultado en el vector en la posicion deseada
        datos[5]=ivacomplemento;//ivacomplemento;
        //this.txtCantidadProducto.setText(null);

        //Hacemos el calculo del subtotal + iva
        double sub = resultdouble + totaliva;
        //Parceamos de double a string
        String subtot=String.valueOf(sub);
        //Mostramos el resultado del subtotal + iva, en el vector en la posicion deseada
        datos[6]=subtot;
        //this.txtCantidadProducto.setText(null);
        // Insertamos en el modelo de la tabla las filas
        modelOrden.addRow(datos);
          //Hacemos la suma del subtotal de la tabla de productos
          //Recorremos las filas en el modelo de la tabla sumando los registros de de la columna subtotal
          for (int i=0; i<modelOrden.getRowCount();i++){
                subto= Double.valueOf(modelOrden.getValueAt(i, 4).toString());
                subtotal=subtotal + subto;
            }
            String resSubt = String.valueOf(subtotal);
            txtSubtotal.setText(resSubt);

            //Recorremos las filas en el modelo de la tabla sumando los registros de de la columna iva
            for (int i=0; i<modelOrden.getRowCount();i++){
                ivatot= Double.valueOf(modelOrden.getValueAt(i, 5).toString());
                ivatotal=ivatotal + ivatot;
            }
            String resIv = String.valueOf(ivatotal);
            txtIva.setText(resIv);

            //Recorremos las filas en el modelo de la tabla sumando los registros de de la columna total
            for (int i=0; i<modelOrden.getRowCount();i++){
                totaltot= Double.valueOf(modelOrden.getValueAt(i, 6).toString());
                sumatotal=sumatotal + totaltot;
            }
            String resTotal = String.valueOf(sumatotal);
            txtTotal.setText(resTotal);

        // ponemos el foco (el cursor) en la caja de texto codigo de producto
        this.txtCodigoProducto.grabFocus();
        //Limpiamos las cajas de texto
        this.txtCodigoProducto.setText(null);
        this.jTextField1.setText(null);
        this.txtCantidadProducto.setText(null);
        this.txtPrecioProducto.setText(null);

    
    }//GEN-LAST:event_btnDetalleActionPerformed

    private void txtCodigoProductoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodigoProductoFocusLost
        // TODO add your handling code here:
       

        buscarProductoCompra = new ProductoBean();
        Vector productoVector = new Vector();
        ProductoBLogic productoBlogic = new ProductoBLogic();
        buscarProductoCompra.setClaveProducto(txtCodigoProducto.getText().toString().trim());

        productoVector = productoBlogic.buscarProductoByCompra(buscarProductoCompra);
        if (productoVector.size() > 0) {
//           deleteRowModelTable();
//           for(int i=0; i<productoVector.size();i++){
            buscarProductoCompra = (ProductoBean) productoVector.elementAt(0);
//           jTextField1.add.addRow(new Object[]{buscarMarca.getCodigoMarca(), buscarMarca.getNombreMarca(),buscarMarca.getIdMarca()});
            jTextField1.setText(buscarProductoCompra.getNombreProducto().toString());
            txtPrecioProducto.setText(buscarProductoCompra.getPrecioCosto().toString());
            String ivaproducto= buscarProductoCompra.getIva(); 
        }



    }//GEN-LAST:event_txtCodigoProductoFocusLost

    public void altaClickCompra() {

        // Variables Locales
        CompraBean sqlBean = new CompraBean();
        Vector datosCompra = new Vector();
        ProveedorBean sqlBeanProveedor = new ProveedorBean();
        Vector datosProveedor = new Vector();
        BancoBean sqlBeanBanco = new BancoBean();
        Vector datosBanco = new Vector();
        EstatusBean sqlBeanEstatus = new EstatusBean();
        Vector datosEstatus = new Vector();

        int idBanco = 0;
        int idProveedor = 0;
        int idEstatus = 0;
        int idCompra = 0;

        // Validamos el Tipo de Accion a Realizar
        switch (this.tipoAccion) {
            // Alta de Cliente
            case 1:

                // Validacion de Campos
                if (jcbProveedor.getSelectedIndex() == 0) {
                    // Mensaje al Usuario
                    JOptionPane.showMessageDialog(null, "Seleccione un Proveedor para generar la Orden de Compra", "Validacion de Campos", JOptionPane.ERROR_MESSAGE);

                } else if (jcbStatusOrdenCompra.getSelectedIndex() == 0) {
                    // Mensaje al Usuario
                    JOptionPane.showMessageDialog(null, "Seleccione un Estatus de la Orden de COmpra", "Validacion de Campos", JOptionPane.ERROR_MESSAGE);
//
//                }else if (jComboBox1.getSelectedIndex()==0 && jTextField4.getText().length()>1){
//                    // Mensaje al Usuario
//                    JOptionPane.showMessageDialog(null,"Seleccione un Banco del Numero de Cheque","Validacion de Campos",JOptionPane.ERROR_MESSAGE);

                } else {
                    // Guardamos el registro de compras
                    //Obtenemos el id de la compra
                    datosCompra = (new CompraBLogic()).getDatosComprasNextId(sqlBean);
                    sqlBean = (CompraBean) datosCompra.elementAt(0);
                    //Vaciamos los datos
                    idCompra = Integer.parseInt(sqlBean.getIdOrdenCompra());

                    //Identificamos el id del banco seleccionado
                    sqlBeanBanco.setNombreBanco(jComboBox1.getSelectedItem().toString());
                    datosBanco = (new BancoBLogic()).getIdBancoNombre(sqlBeanBanco);
                    sqlBeanBanco = (BancoBean) datosBanco.elementAt(0);
                    idBanco = Integer.parseInt(sqlBeanBanco.getIdBanco());

                    //Identificamos el id del proveedor seleccionado
                    sqlBeanProveedor.setNombreProveedor(jcbProveedor.getSelectedItem().toString());
                    datosProveedor = (new ProveedorBLogic()).getIdProveedorByNombre(sqlBeanProveedor);
                    sqlBeanProveedor = (ProveedorBean) datosProveedor.elementAt(0);
                    idProveedor = Integer.parseInt(sqlBeanProveedor.getIdProveedor());

                    //Identificamos el id del estatus seleccionado
                    sqlBeanEstatus.setNombreEstatus(jcbStatusOrdenCompra.getSelectedItem().toString());
                    datosEstatus = (new EstatusBLogic()).getIdEstatusNombre(sqlBeanEstatus);
                    sqlBeanEstatus = (EstatusBean) datosEstatus.elementAt(0);
                    idEstatus = Integer.parseInt(sqlBeanEstatus.getIdEstatus());

                    // Seteamos los Datos
//                    sqlBean.setFechaCaptura(jDateChooser1.getDateFormatString());
//                    sqlBean.setFechaCompletada(jDateChooser2.getDateFormatString());
                    sqlBean.setIdEstatus(Integer.toString(idEstatus));
                    sqlBean.setIdProveedor(Integer.toString(idProveedor));
                    sqlBean.setNoFactura(txtNoFactura.getText());
                    sqlBean.setNoRecibo(txtNoRecibo.getText());
                    sqlBean.setDescuentoOrden(txtDescuento.getText());
                    sqlBean.setSubtotalOrden(txtSubtotal.getText());
                    sqlBean.setIvaOrden(txtIva.getText());
                    sqlBean.setTotalOrden(txtTotal.getText());
                    sqlBean.setPagoContado(jTextField2.getText());
                    sqlBean.setPagoCredito(jTextField3.getText());
                    sqlBean.setNoCheque(jTextField4.getText());
                    sqlBean.setIdBanco(Integer.toString(idBanco));

                    //Insertamos el registro
                    datosCompra = (new CompraBLogic()).execute(sqlBean);
                    //Evaluamos el resultado
                    if (datosCompra.elementAt(0).equals("OK")) {
                        // Mensaje al usuario
                        JOptionPane.showMessageDialog(null, "Orden de Compra Registrado Satisfactoriamente", "Registro", JOptionPane.INFORMATION_MESSAGE);
                        this.setVisible(false);
                    } else {
                        // Mensaje de error
                        JOptionPane.showMessageDialog(null, "Ocurrio un Problema al Momento de Registrar la Orden de Compra", "Registro", JOptionPane.INFORMATION_MESSAGE);
                    }

                }
                break;

            //Modificar
            case 2:

                break;
        }
    }
//}
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new frmAltaCompra().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDetalle;
    public javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JComboBox jcbProveedor;
    private javax.swing.JComboBox jcbStatusOrdenCompra;
    private javax.swing.JTable tblOrdenCompra;
    private javax.swing.JTextField txtCantidadProducto;
    private javax.swing.JTextField txtCodigoProducto;
    private javax.swing.JTextField txtDescuento;
    private javax.swing.JTextField txtIva;
    private javax.swing.JTextField txtNoFactura;
    private javax.swing.JTextField txtNoFactura1;
    private javax.swing.JTextField txtNoRecibo;
    private javax.swing.JTextField txtPrecioProducto;
    private javax.swing.JTextField txtSubtotal;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
